package hlhj.fhp.supreme.activitys

import android.support.v7.widget.LinearLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.lzy.okgo.OkGo
import com.lzy.okgo.model.Response
import hlhj.fhp.supreme.BaseAty
import hlhj.fhp.supreme.R
import hlhj.fhp.supreme.javabean.GetCashHisBean
import hlhj.fhp.supreme.network.Urls
import hlhj.fhp.supreme.utils.JsonCallBack
import hlhj.fhp.supreme.utils.MyUtils
import kotlinx.android.synthetic.main.getcash_his.*

/**
 * Created by Never Fear   on 2018\7\20 0020.
Never More....
 */
class GetCashHisAty :BaseAty() {
    private lateinit var adp:BaseQuickAdapter<GetCashHisBean.DataBean,BaseViewHolder>
    private val datas=ArrayList<GetCashHisBean.DataBean>()
    override fun getContentId(): Int {
            return R.layout.getcash_his
    }

    override fun initView() {
        btExit.setOnClickListener {
            finish()
        }
        adp=object :BaseQuickAdapter<GetCashHisBean.DataBean,BaseViewHolder>(R.layout.getcash_his_item,datas){
            override fun convert(helper: BaseViewHolder?, item: GetCashHisBean.DataBean?) {
                helper?.setText(R.id.itemPrice,"￥${item?.money}")
                helper?.setText(R.id.itemTime,MyUtils.timeStampToStr(item?.create_time?.toLong()!!))
                when(item?.status){
                    "1"->{
                        helper?.setText(R.id.itemStatus,"处理中")
                    }
                    "2"->{
                        helper?.setText(R.id.itemStatus,"已完成")

                    }
                    "3"->{
                        helper?.setText(R.id.itemStatus,"未通过")
                    }
                }
            }
        }
        recyclerview.adapter=adp
        recyclerview.layoutManager=LinearLayoutManager(this@GetCashHisAty,LinearLayoutManager.VERTICAL,false)

        disPatchData()
    }

    private fun disPatchData() {
        OkGo.post<GetCashHisBean>(Urls.BaseUrl+Urls.GETCASHHIS)
                .execute(object :JsonCallBack<GetCashHisBean>(this@GetCashHisAty){
                    override fun onSuccess(response: Response<GetCashHisBean>?) {
                        loadingDialog.dismiss()
                        val cashHisBean = response!!.body()
                        if (cashHisBean.code==1){
                            if (cashHisBean.data!=null){
                                datas.addAll(cashHisBean.data)
                                adp.notifyDataSetChanged()
                            }

                        }else{
                            MyUtils.toast(cashHisBean.msg)
                        }
                    }
                })
    }


}